﻿using AutoOiSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;


namespace AutoOiSystem.ViewModels
{
    public class ScanViewModel : BaseNotifyPropertyChanged
    {
        public delegate void HandDele(string text);
        public event HandDele HandEvent;

      
        //private static ScanViewModel instance;

        //private ScanViewModel()
        //{

        //}

        //public static ScanViewModel GetInstance()
        //{
        //    if (instance == null)
        //    {
        //        instance = new ScanViewModel();
        //    }
        //    return instance;
        //}


        private string _handScanText;


        public string HandScanText
        {
            get { return _handScanText; }
            set
            {
                if (_handScanText != value)
                {
                    _handScanText = value;
                    RaisePropertyChanged("HandScanText");
                }

            }
        }


        private bool _isWinClose;
        public bool IsWinClose
        {
            get { return _isWinClose; }
            set
            {
                if (_isWinClose != value)
                {
                    _isWinClose = value;
                    RaisePropertyChanged("IsWinClose");
                }

            }
        }


        public ICommand HandScanButtonCommand
        {
            get
            {
                return new RelayCommand(
                (param) =>
                {
                    HandScanButton_Click(param);
                }
                , (v) => { return true; });
            }
            set { RaisePropertyChanged("HandScanButtonCommand"); }
        }


        private void HandScanButton_Click(object param)
        {
            try
            {
                //WindowManager.Show("ScanWindow", null);
                //ScanTxt.Focus();
                if (HandScanText.Trim() != null && HandScanText.Trim() != "")
                {
                    HandEvent(HandScanText);

                    IsWinClose = true;
                }
                else
                { MessageBox.Show("扫码框不能为空"); }

               
                //WindowManager.clo
            }
            catch
            { MessageBox.Show("扫码框不能为空"); }
        }




    }
}
